function findShortestSubArray(nums: number[]): number {
	// map { value, [ times, first, last ] };
	const degMap: Map<number, number[]> = new Map();
	let ret = 0;

	for (let i = 0; i < nums.length; i++) {
		const initialArr = degMap.get(nums[i]) || [0, i, 0];
		initialArr[0] += 1;
		initialArr[2] = i;

		degMap.set(nums[i], initialArr);
	}

	let times = 0;
	for (const [_times, _start, _end] of degMap.values()) {
		if (times > _times) {
			continue;
		}

		const dur = _end - _start;

		if (times < _times) {
			times = _times;
			ret = dur;
			continue;
		}

		ret = ret < dur ? ret : dur;
	}

	return ret + 1;
}
